<?php

    namespace yaliSDK\common;

// 基类服务层
    use think\Db;
    use think\Exception;

    class BaseRepository {
        protected $db;
        protected $pms_db;
        public function __construct() {
            try {
                $this->db = Db::connect(config('database.db_config1'));
                $this->pms_db = Db::connect(config('database.db_config2'));
            } catch (Exception $e) {

            }

        }
        function getWebIdByDomain($domain) {
            if ($domain) {
                $_arr = explode('.', $domain);
                if (!empty($_arr[0]) && !empty($_arr[1]) && ($_arr[0]==='h5' || $_arr[0]==='mp' || $_arr[0]==='wms')) {
                    $domain = $_arr[1];
                } else if (!empty($_arr[0]) && !empty($_arr[1]) && ($_arr[1]==='h5' || $_arr[1]==='mp' || $_arr[1]==='wms')) {
                    $domain = $_arr[0];
                }
                $params['domain'] = $domain;
                $set = $this->pms_db->name('domain')->where(['domain' => $domain])->field('web_id')->find();
                if (!empty($set) && !empty($set['web_id'])) {
                    return $set['web_id'];
                }
            }
            return null;
        }

        function  transformNum($num) {
            $new_num =0;
            switch ($num){
                case $num>0&&$num<=9999:
                    $new_num =$num;
                    break;
                case $num>9999&&$num<=9999999: //万
                    $new_num =round($num/10000,2).'w';
                    break;
                case $num>9999999&&$num<=99999999: //千万
                    $new_num =round($num/10000000,2).'kw';
                    break;
                case $num>99999999&&$num<=999999999: //亿
                    $new_num =round($num/10000000,2).'亿';
                    break;
            }
            return $new_num;
        }


    }